<template>
  <div class="login-wrap">
    <el-form
      :model="loginForm"
      :rules="loginFormRules"
      ref="loginRef"
      class="login-form"
    >
      <h3 class="login-title">登陆</h3>
      <el-form-item prop="username">
        <el-input
          v-model="loginForm.username"
          type="text"
          size="large"
          auto-complete="off"
          placeholder="账号"
        >
          <template #prepend>
            <el-icon><i-ep-user /></el-icon>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="loginForm.password"
          type="password"
          size="large"
          auto-complete="off"
          placeholder="密码"
          @keyup.enter="handleLogin"
        >
          <template #prepend>
            <el-icon><i-ep-lock /></el-icon>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-checkbox
          v-model="loginForm.rememberMe"
          label="记住我"
        ></el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button
          :loading="loading"
          type="primary"
          size="large"
          style="width: 100%"
          @click.prevent="handleLogin"
        >
          <span v-if="!loading">登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
        <div
          style="float: right"
          v-if="register"
        >
          <router-link
            class="link-type"
            :to="'/register'"
            >立即注册</router-link
          >
        </div>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <div class="login-footer">
      <span>Copyright © 2023-2023 yuyuan All Rights Reserved.</span>
    </div>
  </div>
</template>

<script setup lang="ts">
defineComponent({ name: 'Login' });
// 注册开关
const register = ref(false);

const { loginForm, loginFormRules } = useLoginForm();
const { loginRef, loading, handleLogin } = useHandleLogin(loginForm);
</script>

<style lang="scss" scoped>
.login-wrap {
  width: 100%;
  height: 100%;
  @include flex-xy;
  background-color: #444141;

  .login-form {
    width: 400px;
    padding: 25px 25px 5px 25px;
    background: #ffffff;
    border-radius: 6px;
    overflow: hidden;

    .login-title {
      margin: 0px auto 30px auto;
      text-align: center;
      color: #707070;
    }
  }

  .login-footer {
    height: 40px;
    line-height: 40px;
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
    color: #fff;
    font-family: Arial;
    font-size: 12px;
    letter-spacing: 1px;
  }
}
</style>
